// API接口封装
import { get, post, put, del } from './request.js'

// 用户相关接口
export const userApi = {
  // 用户登录
  login: (data) => post('/user/user/login', data),
  
  // 用户退出
  logout: () => post('/user/user/logout')
}

// 分类相关接口
export const categoryApi = {
  // 获取分类列表
  getList: (params) => get('/user/category/list', params)
}

// 菜品相关接口
export const dishApi = {
  // 根据分类查询菜品
  getListByCategory: (params) => get('/user/dish/list', params)
}

// 套餐相关接口
export const setmealApi = {
  // 根据分类查询套餐
  getListByCategory: (params) => get('/user/setmeal/list', params),
  
  // 根据套餐ID查询包含的菜品
  getDishesById: (id) => get(`/user/setmeal/dish/${id}`)
}

// 购物车相关接口
export const cartApi = {
  // 添加商品到购物车
  add: (data) => post('/user/shoppingCart/add', data),
  
  // 查看购物车
  getList: () => get('/user/shoppingCart/list'),
  
  // 减少购物车商品数量
  sub: (data) => post('/user/shoppingCart/sub', data),
  
  // 清空购物车
  clear: () => del('/user/shoppingCart/clean')
}

// 地址相关接口
export const addressApi = {
  // 新增地址
  add: (data) => post('/user/addressBook', data),
  
  // 查询用户所有地址
  getList: () => get('/user/addressBook/list'),
  
  // 查询默认地址
  getDefault: () => get('/user/addressBook/default'),
  
  // 根据ID查询地址
  getById: (id) => get(`/user/addressBook/${id}`),
  
  // 修改地址
  update: (data) => put('/user/addressBook', data),
  
  // 删除地址
  delete: (id) => del('/user/addressBook', { id }),
  
  // 设置默认地址
  setDefault: (data) => put('/user/addressBook/default', data)
}

// 订单相关接口
export const orderApi = {
  // 用户下单
  submit: (data) => post('/user/order/submit', data),
  
  // 订单支付
  payment: (data) => put('/user/order/payment', data),
  
  // 查询订单详情
  getDetail: (id) => get(`/user/order/orderDetail/${id}`),
  
  // 历史订单查询
  getHistory: (params) => get('/user/order/historyOrders', params),
  
  // 取消订单
  cancel: (id) => put(`/user/order/cancel/${id}`),
  
  // 催单
  reminder: (id) => get(`/user/order/reminder/${id}`),
  
  // 再来一单
  repetition: (id) => post(`/user/order/repetition/${id}`)
}

// 店铺相关接口
export const shopApi = {
  // 获取营业状态
  getStatus: () => get('/user/shop/status')
}

// 导出所有API
export default {
  user: userApi,
  category: categoryApi,
  dish: dishApi,
  setmeal: setmealApi,
  cart: cartApi,
  address: addressApi,
  order: orderApi,
  shop: shopApi
}
